package com.ymatou.iapi.messageroute.testcase;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.messageroute.parameter.BizTypeEnum;
import com.ymatou.iapi.messageroute.service.SendTradingMsgService;
import com.ymatou.iapi.trading.operate.parameter.BargainGroupService;
import com.ymatou.iapi.trading.operate.parameter.Order;
import com.ymatou.iapi.trading.operate.parameter.PlaceOrderResp;
import com.ymatou.iapi.trading.operate.parameter.PlaceOrderService;
import com.ymatou.iapi.trading.operate.parameter.req.PlaceOrderReq;
import com.ymatou.iapi.trading.operate.service.PlaceOrderCall;
import com.ymatou.iapi.trading.ordersync.parameter.OrderBean;
import com.ymt.base.YmatouEasyCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.OrderCallService;
import com.ymttest.business.service.PaymentProxyCallService;
import com.ymttest.common.enums.CancelOrderTypeEnum;
import com.ymttest.utils.TestDataManager;

/**
 *  消息路由消息通过交易来验证
 */
@TestSuite
public class Ts_MessageRoute_buyer {

	private static OrderCallService orderService;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("消息路由");

	}

	@Before
	public void caseUp() {
		orderService = new OrderCallService();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult("");
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	/**
	* 
	* 一次下单同一个商家1个订单分别使用平台,商家优惠券,订单下面2个商品
	* 不使用优惠券
	* 
	*/
	public static PlaceOrderResp placeOrder(String productName) {

		PlaceOrderResp orderResp = new PlaceOrderResp();

		PlaceOrderReq placeorderBean = PlaceOrderService.getDefaultOrderReq();

		int userId = placeorderBean.getUserId();

		int sellerId = placeorderBean.getOrderGroups().get(0).getSellerId();

		PlaceOrderCall placeorderCall = new PlaceOrderCall();

		try {
			//不使用平台券
			placeorderBean.setYmatouCoupon(null);
			//不使用商家券
			placeorderBean.getOrderGroups().get(0).setSellerCoupon(null);

			placeorderBean.getOrderGroups().get(0).getOrders().get(0)
					.getOrderItems().get(0).setProductName(productName);

			placeorderCall.setData(false, placeorderBean);

			placeorderCall.callService();

			JSONArray orderArray = placeorderCall.getOrderIds();

			List<Order> orderList = new ArrayList<Order>();

			for (int i = 0; i < orderArray.length(); i++) {

				Order order = new Order();

				order.setOrderId(orderArray.getInt(i));
				order.setSellerId(sellerId);

				orderList.add(order);
			}

			int tradingId = placeorderCall.getTradingId();
			// 根据交易号计算需要支付的金额
			BigDecimal payAmount = new OrderCallService()
					.getNeedPrePayAmountOfCashBymainOrderId(tradingId);

			orderResp.setTradingId(tradingId);
			orderResp.setOrderList(orderList);
			orderResp.setPayAmount(payAmount);
			orderResp.setUserId(userId);

		} catch (Exception e) {
			e.printStackTrace();
		}
		return orderResp;
	}

	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	public void Tc_MessageRoute_buyer_000() {
		Logger.start(true, "test");
		SendTradingMsgService.getMsgTaskByOrderId(BizTypeEnum.CANCEL_ORDER,
				"112524635");
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_MessageRoute_buyer_001() {
		Logger.start(true, "订单支付前取消CANCEL_ORDER(用户取消)");
		try {
			PlaceOrderResp placeOrder = PlaceOrderService
					.cancelOrderBeforePaid(CancelOrderTypeEnum.BuyerCancelOrder);
			int orderId = placeOrder.getOrderList().get(0).getOrderId();
			int userId = placeOrder.getUserId();

			// 验证订单未支付前，用户取消，不发通知信息
			SendTradingMsgService.verfiyWithNet(BizTypeEnum.CANCEL_ORDER,
					userId, orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_MessageRoute_buyer_002() {
		Logger.start(true, "订单支付前取消CANCEL_ORDER(商家取消)");
		try {
			PlaceOrderResp placeOrder = PlaceOrderService
					.cancelOrderBeforePaid(CancelOrderTypeEnum.SellerCancelOrder);
			int orderId = placeOrder.getOrderList().get(0).getOrderId();
			int userId = placeOrder.getUserId();

			SendTradingMsgService.verfiyWithNet(BizTypeEnum.CANCEL_ORDER,
					userId, orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}

	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_MessageRoute_buyer_003() {
		Logger.start(true, "订单支付前取消CANCEL_ORDER(系统取消)");
		try {
			PlaceOrderResp placeOrder = PlaceOrderService
					.cancelOrderBeforePaid(CancelOrderTypeEnum.SystemCancelOrder);
			int orderId = placeOrder.getOrderList().get(0).getOrderId();
			int userId = placeOrder.getUserId();

			SendTradingMsgService.verfiyWithNet(BizTypeEnum.CANCEL_ORDER,
					userId, orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_MessageRoute_buyer_004() {
		Logger.start(true, "订单支付前取消CANCEL_ORDER(风控取消)");
		try {
			PlaceOrderResp placeOrder = PlaceOrderService
					.cancelOrderBeforePaid(CancelOrderTypeEnum.SystemCancelOrder);
			int orderId = placeOrder.getOrderList().get(0).getOrderId();
			int userId = placeOrder.getUserId();

			// 风控取消
			Logger.comment("风控检测未通过");
			YmatouEasyCall RiskControlNotifyCall = new YmatouEasyCall("",
					"POST", "JSON");
			String RiskControlNotifyString = "{OrderId:" + orderId
					+ ",ParamExt:{\"Status\":\"rejected\"}}";
			RiskControlNotifyCall
					.setUrl("http://api.trading.operate.ymatou.com/api/Notify/RiskControlNotify");

			RiskControlNotifyCall.setData(RiskControlNotifyString);
			RiskControlNotifyCall.callService();

			SendTradingMsgService.verfiyWithNet(BizTypeEnum.CANCEL_ORDER,
					userId, orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_MessageRoute_buyer_005() {
		Logger.start(true, "卖家取消订单CANCEL_ORDER(已付款返回余额)");
		try {
			PlaceOrderResp placeOrder = PlaceOrderService
					.cancelOrderAfterPaid(CancelOrderTypeEnum.SellerCancelOrder);

			int orderId = placeOrder.getOrderList().get(0).getOrderId();

			int userId = placeOrder.getUserId();

			SendTradingMsgService.verfiyWithNet(BizTypeEnum.CANCEL_ORDER,
					userId, orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_MessageRoute_buyer_006() {
		Logger.start(true, "风控取消订单CANCEL_ORDER(已付款返回余额)");
		try {
			PlaceOrderResp placeOrder = PlaceOrderService.payOrder();

			int orderId = placeOrder.getOrderList().get(0).getOrderId();

			int userId = placeOrder.getUserId();

			// 风控取消
			Logger.comment("风控检测未通过");
			YmatouEasyCall RiskControlNotifyCall = new YmatouEasyCall("",
					"POST", "JSON");
			String RiskControlNotifyString = "{OrderId:" + orderId
					+ ",ParamExt:{\"Status\":\"rejected\"}}";
			RiskControlNotifyCall
					.setUrl("http://api.trading.operate.ymatou.com/api/Notify/RiskControlNotify");

			RiskControlNotifyCall.setData(RiskControlNotifyString);
			RiskControlNotifyCall.callService();

			SendTradingMsgService.verfiyWithNet(BizTypeEnum.CANCEL_ORDER,
					userId, orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_MessageRoute_buyer_007() {
		Logger.start(true, "买家取消订单CANCEL_ORDER(已付款返回余额)");
		try {

			PlaceOrderResp placeOrder = PlaceOrderService
					.cancelOrderAfterPaid(CancelOrderTypeEnum.BuyerCancelOrder);

			int orderId = placeOrder.getOrderList().get(0).getOrderId();

			int userId = placeOrder.getUserId();

			SendTradingMsgService.verfiyWithNet(BizTypeEnum.CANCEL_ORDER,
					userId, orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_MessageRoute_buyer_008() {
		Logger.start(true, "客服取消订单CANCEL_ORDER(已付款返回余额)");
		try {

			PlaceOrderResp placeOrder = PlaceOrderService
					.cancelOrderAfterPaid(CancelOrderTypeEnum.CustomerCancelOrder);

			int orderId = placeOrder.getOrderList().get(0).getOrderId();

			int userId = placeOrder.getUserId();

			SendTradingMsgService.verfiyWithNet(BizTypeEnum.CANCEL_ORDER,
					userId, orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_MessageRoute_buyer_009() {
		Logger.start(true, "卖家取消订单CANCEL_ORDER(已付款原路返回)");
		try {
			// 创建订单
			PlaceOrderResp placeOrderResp = PlaceOrderService
					.placeOrderWithOutCoupon();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();
			BigDecimal payprice = placeOrderResp.getPayAmount();

			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					BigDecimal.ZERO, tradingId, "13");

			// 支付网关支付回调交易
			PaymentProxyCallService.notifyCall("13",
					String.valueOf(thirdTradingId), String.valueOf(payprice),
					userId);

			Thread.sleep(2000);

			// 订单取消
			orderService.cancelOrder(orderId, userId,
					CancelOrderTypeEnum.SellerCancelOrder);

			SendTradingMsgService.verfiyWithNet(BizTypeEnum.CANCEL_ORDER,
					userId, orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_MessageRoute_buyer_010() {
		Logger.start(true, "风控取消订单CANCEL_ORDER(已付款原路返回)");
		try {
			// 创建订单
			PlaceOrderResp placeOrderResp = PlaceOrderService
					.placeOrderWithOutCoupon();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();
			BigDecimal payprice = placeOrderResp.getPayAmount();

			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					BigDecimal.ZERO, tradingId, "13");

			// 支付网关支付回调交易
			PaymentProxyCallService.notifyCall("13",
					String.valueOf(thirdTradingId), String.valueOf(payprice),
					userId);

			Thread.sleep(2000);

			// 风控取消
			Logger.comment("风控检测未通过");
			YmatouEasyCall RiskControlNotifyCall = new YmatouEasyCall("",
					"POST", "JSON");
			String RiskControlNotifyString = "{OrderId:" + orderId
					+ ",ParamExt:{\"Status\":\"rejected\"}}";
			RiskControlNotifyCall
					.setUrl("http://api.trading.operate.ymatou.com/api/Notify/RiskControlNotify");

			RiskControlNotifyCall.setData(RiskControlNotifyString);
			RiskControlNotifyCall.callService();

			SendTradingMsgService.verfiyWithNet(BizTypeEnum.CANCEL_ORDER,
					userId, orderId);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_MessageRoute_buyer_011() {
		Logger.start(true, "买家取消订单CANCEL_ORDER(已付款原路返回)");
		try {

			// 创建订单
			PlaceOrderResp placeOrderResp = PlaceOrderService
					.placeOrderWithOutCoupon();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();
			BigDecimal payprice = placeOrderResp.getPayAmount();

			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					BigDecimal.ZERO, tradingId, "13");

			// 支付网关支付回调交易
			PaymentProxyCallService.notifyCall("13",
					String.valueOf(thirdTradingId), String.valueOf(payprice),
					userId);

			Thread.sleep(2000);

			// 订单取消
			orderService.cancelOrder(orderId, userId,
					CancelOrderTypeEnum.BuyerCancelOrder);

			SendTradingMsgService.verfiyWithNet(BizTypeEnum.CANCEL_ORDER,
					userId, orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_MessageRoute_buyer_012() {
		Logger.start(true, "客服取消订单CANCEL_ORDER(已付款原路返回)");
		try {
			// 创建订单
			PlaceOrderResp placeOrderResp = PlaceOrderService
					.placeOrderWithOutCoupon();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();
			BigDecimal payprice = placeOrderResp.getPayAmount();

			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					BigDecimal.ZERO, tradingId, "13");

			// 支付网关支付回调交易
			PaymentProxyCallService.notifyCall("13",
					String.valueOf(thirdTradingId), String.valueOf(payprice),
					userId);

			Thread.sleep(2000);

			// 订单取消
			orderService.cancelOrder(orderId, userId,
					CancelOrderTypeEnum.CustomerCancelOrder);

			SendTradingMsgService.verfiyWithNet(BizTypeEnum.CANCEL_ORDER,
					userId, orderId);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_MessageRoute_buyer_013() {
		Logger.start(true, "卖家取消订单CANCEL_ORDER(混合支付)");
		try {
			// 创建订单
			PlaceOrderResp placeOrderResp = PlaceOrderService
					.placeOrderWithOutCoupon();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();
			BigDecimal payprice = placeOrderResp.getPayAmount();

			BigDecimal blanceAmount = BigDecimal.TEN;

			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmount, tradingId, "13");

			// 支付网关支付回调交易
			PaymentProxyCallService.notifyCall("13",
					String.valueOf(thirdTradingId),
					String.valueOf(payprice.subtract(blanceAmount)), userId);

			Thread.sleep(2000);

			// 订单取消
			orderService.cancelOrder(orderId, userId,
					CancelOrderTypeEnum.SellerCancelOrder);

			SendTradingMsgService.verfiyWithNet(BizTypeEnum.CANCEL_ORDER,
					userId, orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	//手工验证
	public void Tc_MessageRoute_buyer_014() {
		Logger.start(true, "砍价团取消订单CANCEL_ORDER(已付款返回余额)");
		try {

			PlaceOrderResp placeOrderResp = BargainGroupService.openGroup(null);

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			String bizId = placeOrderResp.getBizId();
			// 取消
			BargainGroupService.notifyOrderBizStatus(bizId, orderId, 1, -1);

			// 验证推送消息

			SendTradingMsgService.verfiyWithNet(BizTypeEnum.CANCEL_ORDER,
					userId, orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_MessageRoute_buyer_015() {
		Logger.start(true, "卖家已接单后取消CANCEL_ORDER(商家取消,退款到余额)");
		try {

			PlaceOrderResp placeOrderResp = PlaceOrderService.acceptOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			// 取消
			orderService.cancelOrder(orderId, sellerId,
					CancelOrderTypeEnum.SellerCancelOrder);
			// 验证推送消息

			SendTradingMsgService.verfiyWithNet(BizTypeEnum.CANCEL_ORDER,
					userId, orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_MessageRoute_buyer_016() {
		Logger.start(true, "卖家已接单后取消CANCEL_ORDER(客服取消,退款到余额)");
		try {

			PlaceOrderResp placeOrderResp = PlaceOrderService.acceptOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			// 取消
			orderService.cancelOrder(orderId, sellerId,
					CancelOrderTypeEnum.CustomerCancelOrder);
			// 验证推送消息

			SendTradingMsgService.verfiyWithNet(BizTypeEnum.CANCEL_ORDER,
					userId, orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	//手工校验
	public void Tc_MessageRoute_buyer_017() {
		Logger.start(true, "砍价团取消订单CANCEL_ORDER(已付款原路返回)");
		try {

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder1(null);

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			BigDecimal payprice = placeOrderResp.getPayAmount();
			String bizId = placeOrderResp.getBizId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal blanceAmount = BigDecimal.TEN;

			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmount, tradingId, "13");

			// 支付网关支付回调交易
			PaymentProxyCallService.notifyCall("13",
					String.valueOf(thirdTradingId),
					String.valueOf(payprice.subtract(blanceAmount)), userId);

			Thread.sleep(2000);

			// 取消
			BargainGroupService.notifyOrderBizStatus(bizId, orderId, 1, -1);

			// 验证推送消息

			SendTradingMsgService.verfiyWithNet(BizTypeEnum.CANCEL_ORDER,
					userId, orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_MessageRoute_buyer_018() {
		Logger.start(true, "卖家已接单后取消CANCEL_ORDER(客服取消,原路返还)");
		try {

			PlaceOrderResp placeOrderResp = PlaceOrderService.acceptOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			// 取消
			orderService.cancelOrder(orderId, sellerId,
					CancelOrderTypeEnum.SellerCancelOrder);
			// 验证推送消息

			SendTradingMsgService.verfiyWithNet(BizTypeEnum.CANCEL_ORDER,
					userId, orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_MessageRoute_buyer_019() {
		Logger.start(true, "卖家已接单ACCEPT_ORDER(用户未传身份证)");
		try {

			PlaceOrderResp placeOrderResp = PlaceOrderService.acceptOrder();
			// 用户未传身份证
			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			int userId = placeOrderResp.getUserId();

			// 验证推送消息

			SendTradingMsgService.verfiyWithNet(BizTypeEnum.ACCEPT_ORDER,
					userId, orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_MessageRoute_buyer_020() {
		Logger.start(true, "商家已发货DISPATCHED");
		try {

			// 创建订单
			PlaceOrderResp placeOrderResp = PlaceOrderService.dispatchedOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int SellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();

			// 验证推送消息

			SendTradingMsgService.verfiyWithNet(BizTypeEnum.DISPATCHED, userId,
					orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	public void Tc_MessageRoute_buyer_021() {
		Logger.start(true, "快速退款FAST_REFUND");
		try {
			// 创建订单
			PlaceOrderResp placeOrderResp = PlaceOrderService
					.placeOrderWithOutCoupon();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();
			BigDecimal payprice = placeOrderResp.getPayAmount();
			// 验证推送消息

			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					BigDecimal.ZERO, tradingId, "13");

			// 订单取消
			orderService.cancelOrder(orderId, userId);

			// 支付网关支付回调交易
			PaymentProxyCallService.notifyCall("13",
					String.valueOf(thirdTradingId), String.valueOf(payprice),
					userId);

			Thread.sleep(2000);

			SendTradingMsgService.verfiyWithNet(BizTypeEnum.FAST_REFUND,
					userId, orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_MessageRoute_buyer_022() {
		Logger.start(true, "商家延长收货DELAY_RECEIVE");
		try {

			PlaceOrderResp placeOrderResp = PlaceOrderService.dispatchedOrder();
			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();

			// 延长收货
			YmatouEasyCall YmatouEasyCall = new YmatouEasyCall("", "POST",
					"JSON");
			OrderBean order = new OrderBean();
			String orderJson = "{\"OrderId\":"
					+ orderId
					+ ",\"OperateUserId\":"
					+ userId
					+ ",\"DelayDay\":1,\"Remark\":\"自动化测试延长信息\",\"OperateUserType\":0}";
			YmatouEasyCall
					.setUrl("http://operate.trading.iapi.ymatou.com/api/Common/DelayReceive");
			YmatouEasyCall.setData(orderJson);
			YmatouEasyCall.callService();

			// 验证推送消息
			SendTradingMsgService.verfiyWithNet(BizTypeEnum.DELAY_RECEIVE,
					userId, orderId);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_MessageRoute_buyer_023() {
		Logger.start(true, "客服延长收货DELAY_RECEIVE");
		try {

			PlaceOrderResp placeOrderResp = PlaceOrderService.dispatchedOrder();
			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();

			// 延长收货
			YmatouEasyCall YmatouEasyCall = new YmatouEasyCall("", "POST",
					"JSON");
			OrderBean order = new OrderBean();
			String orderJson = "{\"OrderId\":"
					+ orderId
					+ ",\"OperateUserId\":"
					+ userId
					+ ",\"DelayDay\":1,\"Remark\":\"自动化测试延长信息\",\"OperateUserType\":2}";
			YmatouEasyCall
					.setUrl("http://operate.trading.iapi.ymatou.com/api/Common/DelayReceive");
			YmatouEasyCall.setData(orderJson);
			YmatouEasyCall.callService();

			// 验证推送消息
			SendTradingMsgService.verfiyWithNet(BizTypeEnum.DELAY_RECEIVE,
					userId, orderId);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_MessageRoute_buyer_024() {
		Logger.start(true, "修改收货人地址CHANGE_ORDER_ADDRESS");
		try {
			// 创建订单

			PlaceOrderResp placeOrderResp = PlaceOrderService.acceptOrder();
			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();

			// 接单后修改收货人地址
			YmatouEasyCall YmatouEasyCall = new YmatouEasyCall("", "POST",
					"JSON");
			OrderBean order = new OrderBean();
			String orderJson = "{\"OrderId\":"
					+ orderId
					+ ",\"UserId\":"
					+ userId
					+ ",\"Address\":\"南京路步行街\",\"PostCode\":\"986574\",\"ReceievePerson\":\"洋码头\",\"Phone\":\"13200000005\",\"Telephone\":\"021-51025140\",\"QQ\":\"100001\",\"Email\":\"Hj02QUQuEXmk@sohu.com\",\"UserType\":\"Normal\",\"ChangeTime\":\"2016-12-26 10:57:26\"}";
			YmatouEasyCall
					.setUrl("http://operate.trading.iapi.ymatou.com/api/Buyer/ChangeOrderAddress");
			YmatouEasyCall.setData(orderJson);
			YmatouEasyCall.callService();

			// 验证推送消息
			SendTradingMsgService.verfiyWithNet(
					BizTypeEnum.CHANGE_ORDER_ADDRESS, userId, orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_MessageRoute_buyer_025() {
		Logger.start(true, "订单中商品名称超过20个字，短信内容商品名称截取前20个字符");
		try {

			String productName = "自动化测试商品" + TestDataManager.getRandomNum(30);

			PlaceOrderResp placeOrder = placeOrder(productName);
			int orderId = placeOrder.getOrderList().get(0).getOrderId();
			int userId = placeOrder.getUserId();

			orderService.cancelOrder(orderId, userId,
					CancelOrderTypeEnum.SellerCancelOrder);

			SendTradingMsgService.verfiyWithNet(BizTypeEnum.CANCEL_ORDER,
					userId, orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_MessageRoute_buyer_026() {
		Logger.start(true, "订单中商品名称含有敏感词，短信内容商品名称用****替代");
		try {

			String productName = "振动棒" + TestDataManager.getRandomNum(30);

			PlaceOrderResp placeOrder = placeOrder(productName);

			int orderId = placeOrder.getOrderList().get(0).getOrderId();
			int userId = placeOrder.getUserId();

			orderService.cancelOrder(orderId, userId,
					CancelOrderTypeEnum.SellerCancelOrder);

			// 验证订单未支付前，商家取消，不发通知信息
			SendTradingMsgService.verfiyWithNet(BizTypeEnum.CANCEL_ORDER,
					userId, orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_MessageRoute_buyer_027() {
		Logger.start(true, "订单中商品名称含有特殊字符,eg ☆★♀♂ O(∩_∩)O");
		try {

			String productName = "测试商品" + TestDataManager.getRandomNum(14)
					+ "☆★♀♂ O(∩_∩)O";

			PlaceOrderResp placeOrder = placeOrder(productName);

			int orderId = placeOrder.getOrderList().get(0).getOrderId();
			int userId = placeOrder.getUserId();

			orderService.cancelOrder(orderId, userId,
					CancelOrderTypeEnum.SellerCancelOrder);

			// 验证订单未支付前，商家取消，不发通知信息
			SendTradingMsgService.verfiyWithNet(BizTypeEnum.CANCEL_ORDER,
					userId, orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_MessageRoute_buyer_028() {
		Logger.start(true, "当前发送时间不在发送的有效时间内，调整到第二天发送");
		try {

			// 创建订单
			PlaceOrderResp placeOrderResp = PlaceOrderService.dispatchedOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int SellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();

			// 验证推送消息

			SendTradingMsgService.verfiyWithNet(BizTypeEnum.DISPATCHED, userId,
					orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	public void Tc_MessageRoute_buyer_029() {
		Logger.start(true, "管理后台，调整消息文案，新文案立即生效");
		try {
			// 创建订单
			PlaceOrderResp placeOrderResp = PlaceOrderService.dispatchedOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int SellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();

			// 验证推送消息
			SendTradingMsgService.verfiyWithNet(BizTypeEnum.DISPATCHED, userId,
					orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	public void Tc_MessageRoute_buyer_030() {
		Logger.start(true, "MQ消息发送消息路由失败，MQ自行补单重发");
		try {
			// 创建订单
			PlaceOrderResp placeOrderResp = PlaceOrderService.dispatchedOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int SellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();

			// 验证推送消息
			SendTradingMsgService.verfiyWithNet(BizTypeEnum.DISPATCHED, userId,
					orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

}